package com.ml.mall.api.sys;

import com.ml.mall.annotations.OperLog;
import com.ml.mall.api.BaseController;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.sys.SysUserRoleNewDto;
import com.ml.mall.bean.req.sys.SysUserRoleQueryDto;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.service.sys.ISysRoleUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
* <p>
    * 用户角色表 前端控制器
    * </p>
*
* @author kyyang
* Created 2021-01-20
*/

@Api(tags = "【auth】用户角色")
@RestController
@RequestMapping("/user_role")
public class SysUserRoleController extends BaseController {

     @Autowired
     private ISysRoleUserService iSysRoleUserService;

    @RequestMapping(method = RequestMethod.POST, path = "/query")
    @ApiOperation("用户角色查询")
//  @RequiresPermissions(PermissionConst.USER_ROLE_QUERY)
    public ApiRestResult sysUserRoleQuery(@Valid @RequestBody SysUserRoleQueryDto sysUserRoleQueryDto) {
        return ApiRestResult.ok(iSysRoleUserService.sysUserRole(sysUserRoleQueryDto));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/new")
    @OperLog(operDesc = "用户角色新建", operModul = "user_role", operType = "new")
    @ApiOperation("用户角色新建")
//  @RequiresPermissions(PermissionConst.USER_ROLE_NEW)
    public ApiRestResult sysUserRoleNew(@Valid @RequestBody SysUserRoleNewDto sysUserRoleNewDto ) {
        iSysRoleUserService.sysUserRoleNew(sysUserRoleNewDto);
        return ApiRestResult.ok();
    }


    @RequestMapping(method = RequestMethod.DELETE, path = "/del")
    @OperLog(operDesc = "角色删除", operModul = "user_role", operType = "del")
    @ApiOperation("角色删除")
//  @RequiresPermissions(PermissionConst.USER_ROLE_DEL)
    public ApiRestResult sysRoleDel(@Valid @RequestBody SysUserRoleNewDto sysUserRoleNewDto ) {
        iSysRoleUserService.sysUserRoleDel(sysUserRoleNewDto);
        return ApiRestResult.ok();
    }
}
